﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace QASampling.QAControl
{
    class QABaseDataGrid : System.Windows.Forms.DataGridView
    {
        public QABaseDataGrid()
        {
            this.AllowUserToAddRows = false;
            this.AllowUserToDeleteRows = false;
            this.AllowUserToOrderColumns = false;
            this.AllowUserToResizeColumns = true;
            this.AllowUserToResizeRows = false;
            this.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            this.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically;
            this.ReadOnly = true;
            this.RowHeadersWidth = 50;
            //--modified by Vincent 20130111 to enable copy all row to excel
            //this.MultiSelect = false;

            this.MultiSelect = true;
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            this.SuspendLayout();
            // 
            // QABaseDataGrid
            // 
            this.RowsAdded += new System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.QABaseDataGrid_RowsAdded);
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
            this.ResumeLayout(false);

        }

        private void QABaseDataGrid_RowsAdded(object sender, System.Windows.Forms.DataGridViewRowsAddedEventArgs e)
        {
            int iLast = e.RowIndex + e.RowCount;
            for (int i = e.RowIndex; i < iLast; i++)
            {
                DataGridViewRow row = this.Rows[i];
                if (!row.IsNewRow)
                    row.HeaderCell.Value = String.Format("{0}", i + 1);
            }            
        }

    }
}
